import 'dart:convert';

import 'package:bruno/bruno.dart';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:sph_shipper/Order/WaybillDetails/ConfirmedTransportationAgreement.dart';
import 'package:sph_shipper/Order/WaybillDetails/UnconfirmedTransportationAgreement.dart';
import 'package:sph_shipper/http/getapi.dart';

import '../../AppConfig/Config.dart';
import '../../AppConfig/LocalStorage.dart';
import '../../AppConfig/RouteAct.dart';
import '../../http/api.dart';
import '../../l10n/messages.dart';

class TransportProtocolNodes extends StatefulWidget {
  const TransportProtocolNodes({super.key, required this.waybillId});
final String waybillId;
  @override
  State<TransportProtocolNodes> createState() => _TransportProtocolNodesState();
}

class _TransportProtocolNodesState extends State<TransportProtocolNodes> {
  List dataList =[];
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getListAction();
  }

void  getListAction(){
  getApiManager.getData(
    context,
    "api/waybill/contract/list",
    {"waybillId":widget.waybillId},
        (responseData)  {
      setState(() {
        dataList=responseData['data'];

      });
    },
  );
}
  @override
  Widget build(BuildContext context) {
    var messages = AppLocalizations.of(context)!;
    final screenSize = MediaQuery.of(context).size;
    return Scaffold(
      backgroundColor: MyColors.backgreyColor,
      appBar: AppBar(
        backgroundColor: Colors.white,
        centerTitle: true,
        title: Text("货物运输协议",style: TextStyle(color: Colors.black,fontWeight: FontWeight.w300,fontSize: 16.sp),),
        leading: IconButton(
          onPressed: () {
            Navigator.pop(context);
          },
          icon: Icon(Icons.arrow_back_ios),
        ),
      ),
      body: Column(
        children: [
          Expanded(
            child: Container(
              child: ListView.builder(
              padding: EdgeInsets.zero,
                shrinkWrap: true,
                itemCount: dataList.length,
                itemBuilder: (BuildContext context,
                    int index) {
                  return GestureDetector(
                      child: Container(
                        margin: EdgeInsets.only(left: 15.w,right: 15.w,top: 10.h),
                        child:Row(
                          children: [
                            if(dataList[index]['status']!=-1)
                            Icon(Icons.circle,color:dataList[index]['effectiveness']==1 ?Colors.green:dataList[index]['effectiveness']==0 ? MyColors.themeColor:Colors.red,size: 10,),
                            if(dataList[index]['status']==-1)
                              Icon(Icons.circle,color:MyColors.authTipColor,size: 10,),

                            SizedBox(width: 16.w,),
                            Container(
                              padding: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h,bottom: 8.h),
                              width: screenSize.width-75.w,
                              decoration: BoxDecoration(
                                color: Colors.white,
                                borderRadius: BorderRadius.all(Radius.circular(10)),
                              ),
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Row(
                                    children: [
                                      if(dataList[index]['effectiveness']==1&&(dataList[index]['status']==0||dataList[index]['status']==1))
                                        Icon(Icons.check_circle_outline,color: Colors.green,),
                                      if(dataList[index]['effectiveness']==-1&&dataList[index]['status']==1)
                                        Icon(Icons.highlight_off,color: Colors.red),
                                      if(dataList[index]['effectiveness']==0&&dataList[index]['status']==0)
                                        Icon(Icons.access_time,color: MyColors.themeColor),
                                      if(dataList[index]['status']==-1)
                                        Icon(Icons.adjust,color: MyColors.authTipColor),
                                      SizedBox(width: 4.w,),
                                      if(dataList[index]['effectiveness']==1&&dataList[index]['status']==1)
                                        Text("已确认",style: TextStyle(color:Colors.green,fontSize: 14.sp),),
                                      if(dataList[index]['status']==1&&dataList[index]['effectiveness']==-1)
                                        Text("已作废",style: TextStyle(color: Colors.red,fontSize: 14.sp),),
                                      if(dataList[index]['effectiveness']==0&&dataList[index]['status']==0)
                                        Text("待确认",style: TextStyle(color: MyColors.themeColor,fontSize: 14.sp),),
                                      if(dataList[index]['status']==-1)
                                        Text("已拒绝",style: TextStyle(color: MyColors.textColor,fontSize: 14.sp),),
                                    ],
                                  ),
                                  SizedBox(height: 10.h,),
                                  Text( dataList[index]['createTime'],style: TextStyle(fontSize: 12.sp,color: MyColors.authTipColor),),
                                ],
                              ),

                            )
                          ],
                        ),
                      ),
                    onTap: () async {
                      if(dataList[index]['status']==0){
                        Navigator.push( context, FadeRoute(page:UnconfirmedTransportationAgreement(wayBillId: dataList[index]['waybillId'], Type: 1,
                        )));
                      }else{
                        Navigator.push( context, FadeRoute(page:ConfirmedTransportationAgreement(wayllBillId: dataList[index]['id'],
                        )));

                      }

                    },
                  );
                  },),
          ),
          ),
          // if((dataList[0]['status']==4||dataList[0]['status']==5)&&dataList[0]['logStatus']==0)
          // Container(
          //   height: 85.h,
          //   color: Colors.white,
          //   padding: EdgeInsets.only(left: 15.w,right: 15.w,top:10.h,bottom: 34.h ),
          //   child: BrnSmallMainButton(
          //     title: '修改协议',
          //     bgColor:MyColors.themeColor,
          //     radius: 30,
          //     fontSize: 16.sp,
          //     width: screenSize.width-30.w,
          //     onTap: () {
          //       BrnToast.show('录需求信息', context);
          //     },
          //   ),
          // ),
        ],
      ),
    );
  }
}
